number = int(input())
num = list()
g = False
block1 = 0
block2 = 1
if number > 9999 or number < 1000:
    num = []
else:
    for i in range (1, 5):
        a = int((str(number)[block1:block2]))
        for i in range (2, a // 2 + 1): 
            if (a % i != 0):
                g = True
            else:
                g = False
                break
        if a == 2 or a == 3:
            g = True
        if g == True:
            num.append(a)
        block1 = block1 + 1 
        block2 = block2 + 1
    block1 = 0
    block2 = 2
    for i in range (1, 4):
        a = int((str(number)[block1:block2]))
        for i in range (2, a // 2 + 1): 
            if (a % i != 0):
                g = True
            else:
                g = False
                break
        if a == 2 or a == 3:
            g = True
        if g == True:
            num.append(a)
        block1 = block1 + 1 
        block2 = block2 + 1
    block1 = 0
    block2 = 3
    for i in range (1, 3):
        a = int((str(number)[block1:block2]))
        for i in range (2, a // 2 + 1): 
            if (a % i != 0):
                g = True
            else:
                g = False
                break
        if a == 2 or a == 3:
            g = True
        if g == True:
            num.append(a)
        block1 = block1 + 1 
        block2 = block2 + 1
    block1 = 0
    block2 = 4
    for i in range (1, 2):
        a = int((str(number)[block1:block2]))
        for i in range (2, a // 2 + 1): 
            if (a % i != 0):
                g = True
            else:
                g = False
                break
        if a == 2 or a == 3:
            g = True
        if g == True:
            num.append(a)
if num == []:
    num = [-1, 0]
print(max(num))